<template>
  <!-- 部分UI代码参考苏苏就是小苏苏 -->
  <view class="index">
    <!-- 用户信息 -->
    <view class="head ">
      <view class="head_box flex-row" style="display: flex; align-items: center; justify-content:left">
        <view class="user_ava">
          <image v-if="avatar" :src="avatar" class="cu-avatar xl round" mode="widthFix">
          </image>
        </view>
        <view>
          <view class="user_name">DreamCoders <text>{{ tip }}</text></view>
          <view class="user_add">新的一天开始了，加油哦~</view>
        </view>
        <!-- <view class="mealBtn" bindtap="ToMealTap">
          <image src="/static/punchCard/meal.png"></image>
          <view class="mealText">{{ is_meal == 2 ? '已订' : '订餐' }}</view>
        </view> -->
      </view>
    </view>

    <view class="contentBox">
      <!-- 打卡记录 -->
      <view class="signRecord">
        <view class="signInfo">上班打卡
          <text class="text-green">{{ record[0].times ? record[0].times : '未打卡' }}</text>
          <view class="sign_address">
            <view class="">{{ record[0].address ? record[0].address : '暂无打卡地址' }}</view>
          </view>
        </view>
        <view class="signInfo">下班打卡
          <text class="text-green">{{ record[1].times ? record[1].times : '未打卡' }}</text>
          <view class="sign_address">
            <view class="">{{ record[1].address ? record[1].address : '暂无打卡地址' }}</view>
          </view>
        </view>
      </view>
      <view class="dateInfo ">
        <text>{{ nowDate }} {{ nowDay }}</text>
      </view>
      <!-- 打卡按钮 -->
      <view class="c_clock flex-column">
        <view class="clock_time flex-column j_c {{status==1?'c1':''}} {{is_out==2 ? 'outArea' : ''}}"
          catchtap="signTap">
          <text>{{ signType > 0 ? "下班打卡" : "上班打卡" }}</text>
          <text>{{ now_time }}</text>
        </view>
        <view class="clock_time_over flex-column j_c  {{status==1?'c2':''}}" catchtap="clockInStart">
          <text>已打卡</text>
          <text>{{ now_time_stop }}</text>
        </view>
      </view>
      <!-- 打卡地址 -->
      <view class="clock_address ">
        <image src="/static/punchCard/add0.png" class="add_icon" />
        <text>{{ current_address }}</text>
      </view>
      <view class="refresh" catchtap="refreshAdd">刷新位置</view>
    </view>
  </view>
</template>

<script>
import util from '@/utils/util.js';

export default {
  data() {
    return {
      signType: 0,
      is_out: 2,
      is_meal: 1,
      now_time: '',
      nowDate: '',
      nowDay: '',
      tip: '',
      current_address: '',
      status: 0,
      latlng: [],
      now_time_stop: '',
      area: {},
      record: [],
    };
  },
  onLoad() {
    this.getCurrentTime();
    this.now_time = this.getTime();
    this.nowDate = util.formatTime(new Date());
    this.nowDay = util.formatDay(new Date());
    this.tip = util.formatSole();
  },
  onShow() {
    this.status = 0;
    this.current_address = '';
  },
  computed: {
    avatar() {
      return this.$store.state.user.avatar;
    },
  },
  methods: {
    getCurrentTime() {
      setInterval(() => {
        this.now_time = this.getTime();
      }, 1000);
    },
    getTime() {
      const hh = new Date().getHours();
      const mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
      const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
      return `${hh}:${mf}:${ss}`;
    },
  },
};
</script>
<style>
page {
  height: calc(100% - 10px)
}

.index {
  margin-top: 10px;
  background: #fff;
  min-height: 100%;
}

.head {
  padding-bottom: 10rpx;
  border-bottom: 2rpx solid #E5E5E5;
}

.head_box {
  padding: 26rpx 28rpx 8px;
  width: 750rpx;
  box-sizing: border-box;
}

.user_ava {
  width: 116rpx;
  height: 116rpx;
  overflow: hidden;
  border-radius: 25%;
  margin-right: 32rpx;
}

.user_name {
  font-size: 32rpx;
  font-weight: 600;
  color: #333333;
  margin-bottom: 18rpx;
}

.user_name text {
  font-size: 24rpx;
  color: #999999;
  font-weight: 400;
  margin-left: 40rpx;
}

.user_add {
  font-size: 28rpx;
  color: #3380F3;
}

.contentBox {
  padding: 44rpx 28rpx;
}

.signRecord {
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
  margin-top: 15px;
}

.dateInfo {
  text-align: center;
  position: relative;
  top: 50px;
  font-size: 35rpx;
}

.c_title {
  font-size: 28rpx;
  color: #666666;
  margin-bottom: 26rpx;
}


.c_section .c_item {
  position: relative;
  font-size: 30rpx;
  font-weight: 600;
  color: #333333;
  padding-left: 40rpx;
  margin-bottom: 110rpx;
}

.c_section text {
  color: #307CED;
  text-overflow: ellipsis;
  overflow: hidden;
  width: 80%;
  white-space: nowrap;
}

.c_section .c_item::before {
  content: '';
  position: absolute;
  width: 18rpx;
  height: 18rpx;
  border: 2rpx solid #999999;
  left: 0;
  top: 50%;
  margin-top: -9rpx;
  border-radius: 50%;
}

.c_section {
  position: relative;
}

.c_section .c_item::after {
  content: '';
  position: absolute;
  width: 2rpx;
  height: 178rpx;
  background: #E6E6E6;
  left: 10rpx;
  top: 34rpx;
}

.c_section view:last-child::after {
  display: none;
}

.start_lo {
  position: absolute;
  top: 30px;
  left: -5px;
}

.start_end {
  position: absolute;
  bottom: -108px;
  left: 20px;
}

.c_clock {
  margin: 180rpx auto 0;
  width: 350rpx;
  height: 380rpx;
  perspective: 1500;
  -webkit-perspective: 1500;
  -moz-perspective: 1500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.clock_time {
  width: 350rpx;
  height: 350rpx;
  margin-bottom: 30rpx;
  position: absolute;
  transition: all 1s;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.clock_time::after {
  content: '';
  top: 0;
  left: 0;
  width: 350rpx;
  height: 350rpx;
  border-radius: 50%;
  position: absolute;
  z-index: 9;
  background: rgba(48, 124, 237, 0.08);
  animation: scale 1s infinite alternate-reverse;
}

/* 已打卡 */
.clock_time_over {
  width: 350rpx;
  height: 350rpx;
  margin-bottom: 30rpx;
  border-radius: 50%;
  background: rgba(48, 124, 237, 0.08);
  position: absolute;
  transition: all 1s;
  backface-visibility: hidden;
  transform: rotateY(-180deg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.clock_time_over::after {
  position: absolute;
  z-index: 11;
  content: '';
  width: 320rpx;
  height: 320rpx;
  background: #C6CED9;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}



.clock_time_over text {
  position: relative;
  z-index: 13;
  color: #FFFFFF;
  display: block;
  width: 100%;
  text-align: center;
}

.clock_time_over text:first-child {
  font-size: 36rpx;
  margin-bottom: 14rpx;
}

.clock_time_over text:last-child {
  font-size: 28rpx;
}

@keyframes scale {

  0% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
  }
}

.clock_time::before {
  position: absolute;
  z-index: 11;
  content: '';
  width: 320rpx;
  height: 320rpx;
  background: rgb(48, 124, 237, 0.79);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.clock_time text {
  position: relative;
  z-index: 13;
  color: #FFFFFF;
  display: block;
  width: 100%;
  text-align: center;
}

.clock_time text:first-child {
  font-size: 36rpx;
  margin-bottom: 14rpx;
}

.clock_time text:last-child {
  font-size: 45rpx;
}

.clock_address {
  text-align: center;
  font-size: 30rpx;
  color: #333333;
  width: 80%;
  margin: 20px auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clock_address text {
  vertical-align: middle;
}

.add_icon {
  width: 28rpx;
  height: 36rpx;
  margin-right: 16rpx;
  vertical-align: middle;
}

.refresh {
  margin-top: 25px;
  color: #307CED;
  display: flex;
  align-items: center;
  justify-content: center;
}



.now_location {
  font-size: 24rpx;
  color: #333333 !important;
}

.upload_box {
  width: 260rpx;
  height: 180rpx;
  background: #F5F5F8;
  border-radius: 5rpx;
}

.upload_box text {
  font-size: 20rpx;
  color: #999 !important;
  font-weight: 100;
}

.camera_icon {
  width: 42rpx;
  height: 44rpx;
  margin-bottom: 10rpx;
}

.clock_img {
  width: 100%;
  height: 100%;
}

.del_icon {
  width: 32rpx;
  height: 32rpx;
  position: absolute;
  right: -4px;
  top: -11rpx;
}

.ative::before {
  background: #307cedc9;
  border: 2rpx solid #307cedc9 !important;
}

.c1 {
  transform: rotateY(180deg)
}

.c1::after {
  animation: none !important;
}

.c2 {
  transform: rotateY(0deg)
}

.mealBtn {
  position: absolute;
  right: 15px;
}

.mealBtn image {
  width: 27px;
  height: 27px;
}

.mealText {
  font-size: 12px;
  color: #999999;
}

.outArea::before {
  background: #f44336 !important;
}

.signInfo {
  width: 48%;
  height: 65px;
  background: #f1f1f1;
  padding: 10px;
  border-radius: 5px;
}

.signInfo text {
  float: inline-end;
}

.sign_address {
  display: flex;
  margin-top: 5px;
}


.sign_address view {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  font-size: 14px;
  margin-top: 1px !important;
  color: #5f5a5a;
}

.text-green {
  color: green;
}
</style>
